﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uber.Messages;
using Uber.HabboHotel.GameClients;

namespace Uber.HabboHotel.Quests
{
    class Quest
    {
        private readonly uint Id;

        public string Type;
        public string Action;
        public int NeedForLevel;
        public int Level;
        public int PixelReward;

        public uint QuestId()
        {
            return this.Id;
        }

        public Quest(uint mId, string mType, string mAction, int mNeedForLevel, int mLevel, int mPixelReward)
        {
            this.Id = mId;
            this.Type = mType;
            this.Action = mAction;
            this.NeedForLevel = mNeedForLevel;
            this.Level = mLevel;
            this.PixelReward = mPixelReward;
        }

        public void Serialize(ServerMessage Message, GameClient Session, Boolean Single)
        {
            Message.AppendStringWithBreak(Type);

            if (Session.GetHabbo().CompletedQuests.Contains(Id))
            {
                Message.AppendInt32(Level);
            }
            else
            {
                Message.AppendInt32(Level - 1); // done count
            }

            Message.AppendInt32(UberEnvironment.GetGame().GetQuestManager().GetHighestLevelForType(Type));

            if (UberEnvironment.GetGame().GetQuestManager().GetHighestLevelForType(Type) == this.Level && Session.GetHabbo().CompletedQuests.Contains(Id) && !Single)
            {
                Message.AppendBoolean(true);
                Message.AppendUInt(0);
                Message.AppendBoolean(false);
                Message.AppendStringWithBreak("");
                Message.AppendStringWithBreak("");
                Message.AppendInt32(0);
                Message.AppendStringWithBreak("");
                Message.AppendInt32(0);
                Message.AppendInt32(0);
            }
            else
            {
                Message.AppendBoolean(false);
                Message.AppendUInt(Id);
                Message.AppendBoolean((Session.GetHabbo().CurrentQuestId == Id) ? true : false);
                Message.AppendStringWithBreak((Action.StartsWith("FIND")) ? "FIND_STUFF" : Action);
                Message.AppendStringWithBreak((this.Id == 1) ? "_1" : "");
                Message.AppendInt32(PixelReward);
                Message.AppendStringWithBreak(Action.Replace("_", ""));
                Message.AppendInt32(Session.GetHabbo().CurrentQuestProgress);
                Message.AppendInt32(NeedForLevel);
            }
        }
    }
}
